<?php
namespace app\api\logic;


class Alipay
{
    //支付宝支付
    static public function payment($body,$order_number,$total_price){
        import('alipay/AopSdk', EXTEND_PATH);
        $aop = new \AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $aop->appId = "2019070265725463";
        $aop->rsaPrivateKey = 'MIIEowIBAAKCAQEAuOcoYUQvBzQENm0ozzbCDePwAwDoQt0BjRg96VVwhvuqh14x
NXXGM6Avc/MjI4+YKWogfExM/+/w7TuU5cj4sxGFyFa8XqB/V0c58Jrm8N6ETIFG
fMj4ts7mVmLZMav+/MexmttrlV3X7lUs5uXiQtu6gvBL/vBP5u7N7HNfsX7qHiUQ
FYODCxoC0OUXiZyfCqL+Dl6pWE0XjhZ6503xfqGv4fcsp0zskoesSZYsQpOK8Iif
es87Jl6JzVUevre83ZKbCwcmhWCQFA0j+2jMC79P6p/T0LCnaTJnQnchoEUK+DUz
05qRfWIo4xVv4ujZCGXQEn0btkV0WvfcdmGOMQIDAQABAoIBAEWgzoTqLydwQBHa
w15ciXC/n/cRlWTwYpAmS9IdGXXLOWkmYDN4eT2hmZz5NwdCIJOf4kHMXcaXLUu4
fxaUuop8E7vgZajgmXNdYAUp38Nel8VTfR6qc3YrrXNkX9OjqC66aDgfXoDtyM14
B6Ofd7ejlLWQFZ4YEo6s6KCcxbFJq57CDWDwn/DvjvoE0dXy5846YPz6GZm3UcWE
OYo+bwS99sZCiqCixJ3xNPArguwtMR4mu183HcH1eqpKaG8OB1uamgwAPdHHymsc
NCmpKGqC8DEDxcP4uZiQvdFj0syY99mrYo+iabjfSJQFBXMsvK81Mm2SIipVrdeK
LWvgWAECgYEA9CkTM8xI0FsrP7Jd7L5CoVL867OYL0sE5KBs+NOQK/OQYGtQYf1y
i5D57huiWdGsokpq2otjHLDxJUtHaOWsT+obfDE8NKGRt1TXgBqnY7qUuP++wz9p
yV9p1gsGdXr1DrU4ZXx4d+mJERNe/nVJImrc9SBodqisqoL/qpiVurECgYEAwd56
+Hr/9LJIPgPMY5RgVOcVWmHhSRT60ftyugkeklGPDysJviF+SyHLnsakIlv9CsiT
3NXrgy5+M3nw4teJJPcDa+rVOgELL3prHxo9iuzqicPIcOft6/S+PfBweTAyQvVv
Ysp5Ffb2vCPtKCO7036yQilKk+QYZcq7rZDu64ECgYEAx6bG0vZbHDVQujdKYop5
xZ0swDgNW67Gg4VDVnz5SVdTWeSmyFoNTl7wYGosabHwroyXr7mHBDEUH2DdNcOJ
EZfnfbhs+MSdeQJhbZleA0jQ0C4geVvjTw08aBB/6ZTvymUZhrMvdy56LIJgjUau
1Pv5TmB/y3fGKXARTBiVZyECgYBfmhTN/+nEgz44xqq92GeAtsvC3E26OkxNzE+R
Cfo3cVy4wCJ3zhB3gFznGVHLV816ydqQpjUTZZP6UoHFe0A4KE9Zol4v0l/vs9Cr
b8c1gQtPkGqBsv2SxAgkhzMPsAK5HkslTm9Ts4uMz7KdfrGa4/mHwtDyCSM23ziZ
qMUJAQKBgA3FecG6XNRhXlI5g7ecioeNtQVidKzd2fz7y/PhqQ2L/TBjvAiHhe26
8wu5Q1dUUBorZOFKfEYYfZfI1emUqROJcRYYpROWz0SG/mpA2FyDOZ5Zb+sX3beU
FfWY+2fi0db8zeLh5sdD+BAHbem32fG+itMjBff/r0JnLw4volcv';//支付宝秘钥
        $aop->format = "json";
        $aop->charset = "UTF-8";
        $aop->signType = "RSA2";
        $aop->alipayrsaPublicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5fpmP2im9x4I27+zF9AGZH3EZVQ1TN+KhRp3Kku2ZpoPbVXkHNitywMaTgIQk3D94hATenRAvb3YzioEj3mC1IrxzZXj35TXn89wzvzSsbbNZeFw1eMO/WtamhJYjHKjZsSeDvX7hIlQO5Dcoa3/IhWnChuGr2l0o2ROh6KU1nxYCTxnNdVC0/w7QiqPpSbluGZ/tW4mzYnS7rqX07aBMQXcvax8hgHllgetPLii8qGHDct1TEafpdSBHToisM6616i1aHy6QHFfK1sa99rT1mmDJJLttBileJEKiNHe1v2oom9V1cwau/cj/1wW7FwEhbu0zWoRtiy8gDhAJPxtIQIDAQAB';//支付宝公钥
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        $request = new \AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数，这里只需要传入业务参数
        $bizcontent = json_encode(array(
            'body'         => $body,
            'subject'      => $body,
            'out_trade_no' => $order_number, //此订单号为商户唯一订单号
            'total_amount' => sprintf('%.2f', $total_price), //保留两位小数
            'product_code' => 'QUICK_MSECURITY_PAY'
        ));
        $request->setNotifyUrl("https://www.ttyjf.cn/api/index/alipay");//异步回调地址
        $request->setBizContent($bizcontent);
//这里和普通的接口调用不同，使用的是sdkExecute
        $response = $aop->sdkExecute($request);
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题
        return $response;
//        return htmlspecialchars($response);//就是orderString 可以直接给客户端请求，无需再做处理。
    }
}
